refactoring
authorJoey Hess <joeyh@joeyh.name>
Thu, 27 Feb 2025 18:54:03 +0000 (14:54 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 27 Feb 2025 18:54:03 +0000 (14:54 -0400)
Backend.hs
Backend/VURL/Utilities.hs
Remote/Web.hs

index 4a7ace6524ca59bd496db36b3d7eab4a60aa169f..de4c7bbee8b7a56afd9df4e4eca41c209615f489 100644 (file)
 module Backend (
        builtinList,
        defaultBackend,
-       defaultHashBackend,
+       hashBackend,
        genKey,
        getBackend,
        chooseBackend,
        lookupBackendVariety,
        lookupBuiltinBackendVariety,
        maybeLookupBackendVariety,
+       unknownBackendVarietyMessage,
        isStableKey,
        isCryptographicallySecureKey,
        isCryptographicallySecure,
@@ -54,6 +55,15 @@ defaultBackend = maybe cache return =<< Annex.getState Annex.backend
        valid name = not (null name)
        lookupname = lookupBackendVariety . parseKeyVariety . encodeBS
 
+{- A hashing backend. Takes git config into account, but
+ - guarantees the backend is cryptographically secure. -}
+hashBackend :: Annex Backend
+hashBackend = do
+       db <- defaultBackend
+       return $ if isCryptographicallySecure db
+               then db
+               else defaultHashBackend
+
 {- Generates a key for a file. -}
 genKey :: KeySource -> MeterUpdate -> Backend -> Annex (Key, Backend)
 genKey source meterupdate b = case B.genKey b of
index 82e5939e7cb981e69c422ebf2a77fa72498871b6..0fdb038ccbf91319ac2663e1ebd2e00004b355b8 100644 (file)
@@ -56,3 +56,11 @@ generateEquivilantKey b f =
                , contentLocation = f
                , inodeCache = Nothing
                }
+
+recordVurlKey :: Backend -> OsPath -> Key -> [Key] -> Annex Bool
+recordVurlKey b f key eks = generateEquivilantKey b f >>= \case
+       Nothing -> return False
+       Just ek -> do
+               unless (ek `elem` eks) $
+                       setEquivilantKey key ek
+               return True
index 4728a64c6acdf86734df29fdaf117cb4a92cbba6..0fdad0e92c01a30796b1ef2f9c7f9d67f2e5c346 100644 (file)
@@ -30,7 +30,7 @@ import Annex.SpecialRemote.Config
 import Logs.Remote
 import Logs.EquivilantKeys
 import Backend
-import Backend.VURL.Utilities (generateEquivilantKey)
+import Backend.VURL.Utilities (recordVurlKey)
 
 import qualified Data.Map as M
 
@@ -169,18 +169,11 @@ downloadKey urlincludeexclude key _af dest p vc =
                | otherwise = return (Just v)
        
        recordvurlkey eks = do
-               -- Make sure to pick a backend that is cryptographically
-               -- secure.
-               db <- defaultBackend
-               let b = if isCryptographicallySecure db
-                       then db
-                       else defaultHashBackend
-               generateEquivilantKey b dest >>= \case
-                       Nothing -> return Nothing
-                       Just ek -> do
-                               unless (ek `elem` eks) $
-                                       setEquivilantKey key ek
-                               return (Just Verified)
+               b <- hashBackend
+               ifM (recordVurlKey b dest key eks)
+                       ( return (Just Verified)
+                       , return Nothing
+                       )
 
 uploadKey :: Key -> AssociatedFile -> Maybe OsPath -> MeterUpdate -> Annex ()
 uploadKey _ _ _ _ = giveup "upload to web not supported"